﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Infrastructure.Crosscutting.Authorize
{
    public class MvcActionClassService : IMvcActionClassService
    {
        Domain.Uow.IRepository<Domain.Entity.MvcActionClass>  actionClassRepository;

        public MvcActionClassService(Domain.Uow.IRepository<Domain.Entity.MvcActionClass> actionClass)
        {
            if (actionClass == null)
            {
                throw new ArgumentNullException("actionClassRepository is null");
            }
            actionClassRepository = actionClass;
        }

        public Domain.Entity.MvcActionClass Add(Domain.Entity.MvcActionClass actionClass, Domain.Entity.User operUser)
        {
            try
            {
                actionClassRepository.Add(actionClass);
                actionClassRepository.Uow.Commit();
                //add log
            }
            catch (Exception ex)
            {
            }
            return actionClass;
        }

        public bool Delete(Domain.Entity.MvcActionClass actionClass, Domain.Entity.User operUser)
        {
            var res = false;
            try
            {
                actionClass.State = false;
                actionClassRepository.Modify(actionClass);
                actionClassRepository.Uow.Commit();
                res = true;
                //add log
            }
            catch (Exception ex)
            {
            }
            return res;
        }

        public bool DeleteTrue(Domain.Entity.MvcActionClass actionClass, Domain.Entity.User operUser)
        {
            var res = false;
            try
            {
                actionClassRepository.Delete(actionClass);
                actionClassRepository.Uow.Commit();
                res = true;
                //add log
            }
            catch (Exception ex)
            {
            }
            return res;
        }

        public bool Delete(IList<int> idList, Domain.Entity.User operUser)
        {
            var res = false;
            var delete = actionClassRepository.GetList(e => idList.Contains(e.Id));
            foreach (var item in delete)
            {
                item.State = false;
                actionClassRepository.Modify(item);
            }
            try
            {
                actionClassRepository.Uow.Commit();
                res = true;
                //add log
            }
            catch (Exception ex)
            {
            }
            return res;
        }

        public bool DeleteTrue(IList<int> idList, Domain.Entity.User operUser)
        {
            var res = false;
            var delete = actionClassRepository.GetList(e => idList.Contains(e.Id));
            foreach (var item in delete)
            {
                item.State = false;
                actionClassRepository.Delete(item);
            }
            try
            {
                actionClassRepository.Uow.Commit();
                res = true;
                //add log
            }
            catch (Exception ex)
            {
            }
            return res;
        }

        public bool Modify(Domain.Entity.MvcActionClass actionClass, Domain.Entity.User operUser)
        {
            var res = false;
            try
            {
                actionClassRepository.Modify(actionClass);
                actionClassRepository.Uow.Commit();
                res = true;
                //add log
            }
            catch (Exception ex)
            {
            }
            return res;
        }

        public IQueryable<Domain.Entity.MvcActionClass> GetList()
        {
            var data = actionClassRepository.GetList();
            return data;
        }

        public Domain.Entity.MvcActionClass Get(int id)
        {
            var data = actionClassRepository.Get(id);
            return data;
        }
    }
}
